package com.totoro.tyrank.enums;


import com.totoro.tyrank.constants.CommandConst;
import com.totoro.tyrank.executor.command.MainCommandExecutor;
import com.totoro.tyrank.executor.command.impl.*;
import com.totoro.tyrank.utils.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author Totoro
 * @version 0.1.0
 * @date 2025/7/28 - 19:21
 * @description Command Enum Class
 **/
@AllArgsConstructor
public enum CommandEnum {
    OPEN_COMMAND(CommandConst.OPEN, new OpenCommandExecutor()),
    ALL_COMMAND(CommandConst.ALL, new AllCommandExecutor()),
    CURRENT_COMMAND(CommandConst.CURRENT, new CurrentCommandExecutor()),
    HISTORY_COMMAND(CommandConst.HISTORY, new HistoryCommandExecutor()),
    HELP_COMMAND(CommandConst.HELP, new HelpCommandExecutor()),
    RELOAD_COMMAND(CommandConst.RELOAD, new ReloadCommandExecutor());

    private final String commandArg;
    @Getter private final MainCommandExecutor mainCommandExecutor;

    /**
     * @author totoro
     * @description 根据命令参数获取对应的命令枚举值
     * @date  19:23
     * @param commandArg - 命令参数字符串
     * @return com.totoro.tyrank.enums.CommandEnum 返回匹配的命令枚举值，未果则返回帮助命令
     **/
    public static CommandEnum getValue(String commandArg) {
        if (StrUtil.isBlank(commandArg)) return HELP_COMMAND;
        return Arrays.stream(values()).
                filter(value -> value.commandArg.equalsIgnoreCase(commandArg)).
                findFirst().orElse(HELP_COMMAND);
    }
}
